home *** CD-ROM | disk | FTP | other *** search
Java Source | 1997-05-14 | 19.7 KB | 765 lines |
- import ComponentApp;
- import ButtonObject;
-
- public class DynaButtonsComp extends ComponentApp
- {
- int backgroundStyle =0 ;
- DAssetManager assMan = null;
- int upID = 0, downID = 0;
- String Orientation = "";
- String ButtonImage = "", HighliteImage = "";
- String paramButtonImage = "", paramHighliteImage = "";
- int backgroundColor = 0;
- String backgroundImage = "";
- String paramBackgroundImage = "";
- int textJustification = 0;
- int textAlignment = 0;
- int fontColor = 0;
- int highliteFontColor = 0;
- String buttonFont = "";
- boolean italic = false;
- boolean bold = false;
- int fontSize = 0;
- ButtonObject buttonList = null;
- DDrawJava theJavaApplet = null;
- String compImage = "";
- int imgX = 0,imgY = 0;
- String indent = " ";
- String cb;
-
- void SetPropertyValues()
- {
- theJavaApplet.ResetParams();
-
- // used to speed up loading under Netscape 3.0+
- theJavaApplet.setHTMLBetween("ARCHIVE=DynaButtons.zip");
-
- // used to speed up loading under IE 3.0
- theJavaApplet.AddParam("cabbase",typeString,"DynaButtons.cab");
-
- theJavaApplet.AddParam("Orientation",typeString,Orientation);
- theJavaApplet.AddParam("ButtonImage",typeString,paramButtonImage);
- theJavaApplet.AddParam("HighliteImage",typeString,paramHighliteImage);
- theJavaApplet.AddParam("TextJustification",typeString,Integer.toString(textJustification));
- theJavaApplet.AddParam("TextAlignment",typeString,Integer.toString(textAlignment));
- theJavaApplet.AddParam("ButtonFont",typeString,buttonFont);
- theJavaApplet.AddParam("FontSize",typeString,Integer.toString(fontSize));
- theJavaApplet.AddParam("FontColor",typeString,Integer.toString(fontColor));
- theJavaApplet.AddParam("HighliteFontColor",typeString,Integer.toString(highliteFontColor));
-
- if (bold)
- theJavaApplet.AddParam("Bold",typeString,"True");
- if (italic)
- theJavaApplet.AddParam("Italic",typeString,"True");
-
- if (backgroundStyle == BackgroundStyle.SolidColor)
- theJavaApplet.AddParam("BackgroundColor",typeString,Integer.toString(backgroundColor));
- else if (backgroundStyle == BackgroundStyle.Image)
- theJavaApplet.AddParam("BackgroundImage",typeString,paramBackgroundImage);
-
- ButtonObject tempList = buttonList.getNext();
-
- // start this loop at 0 for the applet
-
- for (int i=0; tempList != null; i++)
- {
- if (tempList.getSubButtonsExist())
- {
- if (tempList.getText().compareTo("") == 0)
- theJavaApplet.AddParam("ButtonText"+i,typeString," ");
- else
- theJavaApplet.AddParam("ButtonText"+i,typeString,tempList.getText());
-
- // first button is a dummy
- ButtonObject subList = tempList.getSubButtons().getNext();
-
- for (int j=0; subList != null; j++)
- {
- if (subList.getText().compareTo("") == 0)
- {
- theJavaApplet.AddParam("ButtonText"+i+"_"+j,typeString," ");
- theJavaApplet.AddParam("URL"+i+"_"+j,typeString," ");
- }
- else
- {
- theJavaApplet.AddParam("ButtonText"+i+"_"+j,typeString,subList.getText());
- theJavaApplet.AddParam("URL"+i+"_"+j,typeString,subList.getURL());
- }
-
- subList = subList.getNext();
- }
- }
- else
- {
- if (tempList.getText().compareTo("") == 0)
- theJavaApplet.AddParam("ButtonText"+i,typeString," ");
- else
- {
- String buttonText = assMan.GetAssetName(Integer.parseInt(tempList.getID(),10));
- theJavaApplet.AddParam("ButtonText"+i,typeString,buttonText);
- }
-
- theJavaApplet.AddParam("URL"+i,typeString,tempList.getURL());
- }
-
- tempList = tempList.getNext();
- }
- }
-
- public String onInstall(DAssetManager cam, String codebase)
- {
- assMan = cam;
- compImage = codebase + "DYNBUTTON.gif";
- return "DynaButtons";
- }
-
- public void onInspect(CStringArray Names,CStringArray Types)
- {
- Names.Set("Orientation");
- Types.Set("Set(Horizontal|Vertical)");
- Names.Set("Number of Buttons");
- Types.Set(typeJavaCollection);
- ButtonObject tempList = buttonList.getNext();
-
- for (int i=1; tempList != null; i++)
- {
- if (tempList.getSubButtonsExist())
- {
- Names.Set("Button "+i);
- Types.Set(typeString);
- Names.Set("Use Sub-Buttons "+i);
- Types.Set("Set(Yes|No)");
- Names.Set("Number Sub-Buttons "+i);
- Types.Set(typeJavaCollection);
- ButtonObject subList = tempList.getSubButtons().getNext();
-
- for (int j=1; subList != null; j++)
- {
- Names.Set(indent + "Sub-Button "+i+","+j);
- Types.Set(typeLink);
- subList = subList.getNext();
- }
- }
- else
- {
- Names.Set("Button "+i);
- Types.Set(typeLink);
- Names.Set("Use Sub-Buttons "+i);
- Types.Set("Set(Yes|No)");
- }
-
- tempList = tempList.getNext();
- }
- }
-
- private void modifyNumButtons(int newLength, ButtonObject currentList)
- {
- int currentLength = countButtons(currentList);
-
- if (newLength < currentLength) // make the list shorter
- {
- for (int i=0; i < newLength; i++)
- {
- currentList = currentList.getNext();
- }
- currentList.setNext(null);
- }
- else if (newLength > currentLength) // make the list longer
- {
- for (int i=0; i < newLength; i++)
- {
- if (currentList.getNext() == null)
- {
- currentList.setNext(new ButtonObject());
- }
- currentList = currentList.getNext();
- }
- }
- }
-
- private int countButtons(ButtonObject buttonList)
- {
- int num=0;
-
- // the first button is a dummy
- ButtonObject tempList = buttonList.getNext();
-
- while (tempList != null)
- {
- num++;
- tempList = tempList.getNext();
- }
-
- return num;
- }
-
-
- public String PropertyListener(String Event,String Value,int Get, int propIndex, IDInspector insp)
- {
- // return a value
-
- if (Get == 1)
- {
- if (Event.compareTo("Orientation") == 0)
- {
- if (Orientation.compareTo("Horizontal") == 0)
- return ("0");
- else
- return ("1");
- }
- else if (Event.compareTo("Number of Buttons") == 0)
- {
- return Integer.toString(countButtons(buttonList));
- }
- else
- {
- // the first button is a dummy
- ButtonObject tempList = buttonList.getNext();
-
- for (int i=1; tempList != null; i++)
- {
- if (Event.compareTo("Use Sub-Buttons "+i)==0)
- {
- if (tempList.getSubButtonsExist())
- return ("0");
- else
- return ("1");
- }
-
- if (Event.compareTo("Button "+i) == 0)
- {
- if (tempList.getSubButtonsExist())
- return (tempList.getText());
- else
- return (tempList.getID());
- }
-
- ButtonObject subList = tempList.getSubButtons();
-
- if (Event.compareTo("Number Sub-Buttons "+i) ==0)
- {
- return Integer.toString(countButtons(subList));
- }
-
- subList = subList.getNext();
-
- for (int j=1; subList != null; j++)
- {
- if (Event.compareTo(indent + "Sub-Button "+i+","+j) == 0)
- {
- return (subList.getID());
- }
-
- subList = subList.getNext();
- }
-
- tempList = tempList.getNext();
- }
- }
- }
- else // user set a value
- {
- if (Event.compareTo("Orientation")==0)
- {
- if (Value.compareTo("0") == 0)
- {
- Orientation = "Horizontal";
- }
- else
- {
- Orientation = "Vertical";
- }
-
- debug("\r\nrandom:");
- checkList(buttonList);
-
- modifyImageSize();
- }
- else if (Event.compareTo("Number of Buttons") == 0)
- {
- int NumButtons = Integer.parseInt(Value,10);
-
- if (NumButtons > 20)
- NumButtons = 20;
-
- modifyNumButtons(NumButtons,buttonList);
- modifyImageSize();
- }
- else
- {
- ButtonObject tempList = buttonList.getNext();
-
- for (int i=1; tempList != null; i++)
- {
- if (Event.compareTo("Button "+i)==0)
- {
- if (tempList.getSubButtonsExist())
- {
- tempList.setText(Value);
- }
- else
- {
- tempList.setID(Value);
- tempList.setText(assMan.GetAssetName(Integer.parseInt(Value,10)));
- }
- }
- else if (Event.compareTo("Use Sub-Buttons "+i)==0)
- {
- if (Value.compareTo("0") == 0)
- {
- tempList.setSubButtonsExist(true);
-
- if (insp != null)
- insp.OnPropertyChanged(-1);
- }
- else
- {
- tempList.setSubButtonsExist(false);
-
- if (insp != null)
- insp.OnPropertyChanged(-1);
- }
- modifyImageSize();
- }
- else if (Event.compareTo("Number Sub-Buttons "+i)==0)
- {
- int NumButtons = Integer.parseInt(Value,10);
-
- if (NumButtons > 20)
- NumButtons = 20;
-
- modifyNumButtons(NumButtons,tempList.getSubButtons());
- modifyImageSize();
- }
- else
- {
- // go through the subButtons
-
- ButtonObject subList = tempList.getSubButtons().getNext();
-
- for (int j=1; subList != null; j++)
- {
- if (Event.compareTo(indent + "Sub-Button "+i+","+j) == 0)
- {
- subList.setID(Value);
- subList.setText(assMan.GetAssetName(Integer.parseInt(Value,10)));
- }
-
- subList = subList.getNext();
- }
- }
- tempList = tempList.getNext();
- }
- }
-
- SetPropertyValues();
- }
- return ("");
- }
-
- private void modifyImageSize()
- {
- int width=0;
- int height=0;
- ButtonObject tempList = buttonList.getNext();
-
- if (Orientation.compareTo("Horizontal") == 0)
- {
- width = countButtons(buttonList); // width is the top buttons,
-
- // height is 1 + max sub buttons
-
- while(tempList != null)
- {
- if (height == 0)
- height = 1;
-
- if (tempList.getSubButtonsExist())
- {
- // add 1 to account for the top level buttons
- int numSubButtons = countButtons(tempList.getSubButtons()) + 1;
-
- if (numSubButtons > height)
- height = numSubButtons;
- }
- tempList = tempList.getNext();
- }
- }
- else
- {
- height = countButtons(buttonList); // width is the top buttons,
-
- // height is max depth, accounting for the parent depth
-
- for (int i=1; tempList != null; i++)
- {
- if (width == 0)
- width = 1;
-
- if (tempList.getSubButtonsExist())
- {
- width = 2;
-
- // add 1 to account for the top level buttons
- int numSubButtons = countButtons(tempList.getSubButtons()) + i;
-
- if (numSubButtons > height)
- height = numSubButtons;
- }
- tempList = tempList.getNext();
- }
- }
-
- theJavaApplet.SetSize((width*imgX), (height*imgY));
- }
-
- public void onDrop(IDLayout layout, IDRect r, int fDrop)
- {
- if (fDrop == ActivateState.Drop) // the first time the component is dropped
- {
- theJavaApplet = new DDrawJava();
- theJavaApplet.SetStyle(DrawObjectStyle.NonResizable,DrawObjectStyle.NonResizable);
- theJavaApplet.setStretch(PictureStretchMode.DRAW_STRETCHED);
-
- // the first button is a dummy
- buttonList = new ButtonObject();
- buttonList.setNext(new ButtonObject());
-
- theJavaApplet.SetPositionRect(r.getLeft(), r.getTop(), r.getLeft(), r.getTop());
- Orientation = "Horizontal";
- theJavaApplet.setImageFile(compImage);
- theJavaApplet.setUsePictureText(true);
- theJavaApplet.setPictureText("DynaButtons");
-
- cb = theJavaApplet.getCodeBase();
- theJavaApplet.setAppletFileName(cb + "DynaButtons.class");
- theJavaApplet.AddAdditionalAppletFile(cb + "PopButton.class");
- theJavaApplet.AddAdditionalAppletFile(cb + "PopObject.class");
- theJavaApplet.AddAdditionalAppletFile(cb + "DynaButtons.cab");
- layout.AddObject(theJavaApplet);
- }
- if (fDrop != ActivateState.Paste && fDrop != ActivateState.Undo) {
- updateSiteLook(IAssetContext.Local);
- SetPropertyValues();
- }
- }
-
-
- private void updateSiteLook(int context)
- {
- IDLayout layout = theJavaApplet.getLayout();
- IDSite site = layout.getSite();
- IDStyle style = site.getCurrentStyle();
-
- // first check the layout background, then the site style
-
- backgroundStyle = layout.getBackgroundStyle();
-
- if (backgroundStyle != BackgroundStyle.None)
- {
- if (backgroundStyle == BackgroundStyle.SolidColor)
- backgroundColor = layout.getBackgroundColor();
- else if (backgroundStyle == BackgroundStyle.Image)
- {
- int backID = assMan.AddAsset(layout.getBackgroundImage(),IAssetType.Image,"");
- backgroundImage = assMan.GetAssetRelativeLocation(backID,context,1);
- }
- }
- else // use the site style
- {
- backgroundStyle = style.getBackgroundStyle();
-
- if (backgroundStyle == BackgroundStyle.SolidColor)
- backgroundColor = style.getBackgroundColor();
- else if (backgroundStyle == BackgroundStyle.Image)
- {
- int backID = assMan.AddAsset(style.getBackgroundImage(),IAssetType.Image,"");
- backgroundImage = assMan.GetAssetRelativeLocation(backID,context,1);
- }
- }
-
- textJustification = 5; // center center set later
- textAlignment = style.getButtonTextAlign();
- fontColor = style.getButtonFontColor();
- highliteFontColor = style.getButtonDownFontColor();
- IDFont font = style.getButtonFont();
- buttonFont = font.getName();
- fontSize = font.getPoint();
- bold = font.getBold();
- italic = font.getItalic();
-
- String buttonUp = style.getButtonUpImage();
-
- //debug("buttonUp: "+buttonUp);
-
- if (buttonUp == null || buttonUp.compareTo("") == 0)
- buttonUp = cb + "transButton.gif";
-
- String buttonDown = style.getButtonDownImage();
-
- if (buttonDown == null || buttonDown.compareTo("") == 0)
- buttonDown = cb + "transButton.gif";
-
- //
- // DS 1/29/87
- // remove old assets before adding new ones
- //
- RemoveAssets();
- // DS 1/29/87
-
- upID = assMan.AddAsset(buttonUp,IAssetType.Image,"");
- downID = assMan.AddAsset(buttonDown,IAssetType.Image,"");
- ButtonImage = assMan.GetAssetRelativeLocation(upID,context,1);
- HighliteImage = assMan.GetAssetRelativeLocation(downID,context,1);
- IDSize buttonSize = style.getButtonSize();
- //
- // DS fix 1/28/97, no style button image fix
- //
- if (buttonSize != null) {
- imgX = buttonSize.getWidth();
- imgY = buttonSize.getHeight();
- } else {
- //
- // default to plain button size
- //
- imgX = 100;
- imgY = 35;
- }
- // DS fix 1/28/97
-
- modifyImageSize();
- }
-
- private void debug(String out)
- {
- //DMessageBox d = new DMessageBox();
- //d.Trace(out + "\r\n");
- }
-
-
- private void setAllUrls(int context)
- {
- ButtonObject tempList = buttonList.getNext();
-
- for (int i=1; tempList != null; i++)
- {
- String theURL = assMan.GetAssetRelativeLocation(Integer.parseInt(tempList.getID(),10),context,1);
- tempList.setURL(theURL);
-
- if (tempList.getSubButtonsExist())
- {
- ButtonObject subList = tempList.getSubButtons().getNext();
-
- for (int j=1; subList != null; j++)
- {
- String subURL = assMan.GetAssetRelativeLocation(Integer.parseInt(subList.getID(),10),context,1);
- subList.setURL(subURL);
- subList = subList.getNext();
- }
- }
- tempList = tempList.getNext();
- }
- }
-
-
- public void onPublish(DAssetManager asm, int context)
- {
- //debug ("<publish> length of original: "+countButtons(buttonList));
-
- updateSiteLook(context);
- setAllUrls(context);
-
- if (context == IAssetContext.Preview)
- {
- paramButtonImage = "file:///" + ButtonImage;
- paramHighliteImage = "file:///" + HighliteImage;
- paramBackgroundImage = "file:///" + backgroundImage;
- }
- else
- {
- paramButtonImage = ButtonImage;
- paramHighliteImage = HighliteImage;
- paramBackgroundImage = backgroundImage;
- }
-
- SetPropertyValues();
- IDRect thePosition=theJavaApplet.getObjectRect();
- theJavaApplet.AddParam("X Position",typeString,Integer.toString(thePosition.getLeft()));
- theJavaApplet.AddParam("Y Position",typeString,Integer.toString(thePosition.getTop()+7));
- }
-
- //
- // DS 1/29/87 add RemoveAssets() fucntion
- //
- protected void RemoveAssets() {
- if (upID != 0) {
- assMan.RemoveAsset(upID);
- assMan.RemoveAsset(downID);
- }
- }
-
- //
- // 2/5/97 leak fix
- //
- protected void RemoveOneAsset(String assetIDStr) {
- int assetID = Integer.parseInt(assetIDStr,10);
- if (assetID != 0)
- assMan.RemoveAsset(assetID);
- }
-
- //
- // 2/5/97 leak fix
- //
- protected void CopyOneAsset(String assetIDStr) {
- int assetID = Integer.parseInt(assetIDStr,10);
- if (assetID != 0)
- assMan.CopyAsset(assetID);
- }
-
- protected void finalize()
- {
- RemoveAssets();
-
- ButtonObject tempList = buttonList.getNext();
-
- for (int i=1; tempList != null; i++)
- {
- //
- // 2/5/97 leak fix
- //
- RemoveOneAsset(tempList.getID());
- if (tempList.getSubButtonsExist())
- {
- ButtonObject subList = tempList.getSubButtons().getNext();
-
- for (int j=1; subList != null; j++)
- {
- //
- // 2/5/97 leak fix
- //
- RemoveOneAsset(subList.getID());
- subList = subList.getNext();
- }
- }
- tempList = tempList.getNext();
- }
-
- }
-
- public void onCopy()
- {
- debug("in onCopy()");
-
- Orientation = new String(Orientation);
- ButtonImage = new String(ButtonImage);
- HighliteImage = new String(HighliteImage);
- paramButtonImage = new String(paramButtonImage);
- paramHighliteImage = new String(paramHighliteImage);
- backgroundImage = new String(backgroundImage);
- buttonFont = new String(buttonFont);
- compImage = new String(compImage);
- indent = new String(indent);
-
- assMan.CopyAsset(upID);
- assMan.CopyAsset(downID);
-
- // copy the linked list
-
- ButtonObject copyButtonList = new ButtonObject();
- ButtonObject copyTempList = copyButtonList;
-
- debug ("<copy> length of original: "+countButtons(buttonList));
-
- ButtonObject tempList = buttonList.getNext();
-
- debug("about to copy list");
-
- for (int i=1; tempList != null; i++)
- {
- debug("in copy list");
-
- copyTempList.setNext(new ButtonObject());
- copyTempList = copyTempList.getNext();
-
- //
- // 2/5/97 leak fix
- //
- CopyOneAsset(tempList.getID());
-
- copyTempList.setID(tempList.getID());
- copyTempList.setText(tempList.getText());
- copyTempList.setURL(tempList.getURL());
-
- debug("copied: "+i);
-
- if (tempList.getSubButtonsExist())
- {
- copyTempList.setSubButtonsExist(true);
-
- ButtonObject subList = tempList.getSubButtons().getNext();
- ButtonObject copySubList = copyTempList.getSubButtons();
-
- for (int j=1; subList != null; j++)
- {
- copySubList.setNext(new ButtonObject());
- copySubList = copySubList.getNext();
-
- //
- // 2/5/97 leak fix
- //
- CopyOneAsset(subList.getID());
- copySubList.setID(subList.getID());
- copySubList.setText(subList.getText());
- copySubList.setURL(subList.getURL());
- subList = subList.getNext();
- }
- }
- tempList = tempList.getNext();
- }
- /*
- debug("length of copy: "+countButtons(copyButtonList));
-
-
- debug("\r\nthe original:");
- checkList(buttonList);
-
- debug("\r\nthe copy:");
- checkList(copyButtonList);
- */
- buttonList = copyButtonList;
- }
-
-
- void checkList(ButtonObject list)
- {
- /*
- debug("in checkList()");
-
- ButtonObject tempList = list.getNext();
-
- for (int i=1; tempList != null; i++)
- {
- debug("checking: "+i);
-
- debug("id: "+tempList.getID());
- debug("text: "+tempList.getText());
- debug("url: "+tempList.getURL());
-
- if (tempList.getSubButtonsExist())
- {
- debug("sub-buttons exist for: "+i);
- ButtonObject subList = tempList.getSubButtons().getNext();
-
- for (int j=1; subList != null; j++)
- {
- debug("sub id: "+subList.getID());
- debug("sub text: "+subList.getText());
- debug("sub url: "+subList.getURL());
- }
- }
- tempList = tempList.getNext();
- }
- */
- }
- }
-